package com.cskaoyan.market.admin.controller;

import com.cskaoyan.market.admin.service.AdminRegionService;
import com.cskaoyan.market.db.vo.MarketRegionVo;
import com.cskaoyan.market.util.JacksonUtil;
import com.cskaoyan.market.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


@RestController
@RequestMapping("/admin/region")
public class AdminRegionController{
    // 获取adminRegion的Service层对象
    @Autowired
    AdminRegionService adminRegionService;

    /**
     * 商城行政区域查询列表
     * @param request
     * @param response
     */
    @GetMapping("/list")
    private void list(HttpServletRequest request, HttpServletResponse response) throws IOException {
        // 调用Service层进行查询
        List<MarketRegionVo> marketRegionVoList = adminRegionService.list();
        // 响应
        Object ok = ResponseUtil.okList(marketRegionVoList);
        response.getWriter().println(JacksonUtil.getObjectMapper().writeValueAsString(ok));
    }

}